package com.zcgame.customview.fresh

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.compose.ui.unit.dp
import com.zcgame.base.utils.DensityUtil
import com.zcgame.customview.R

/**
 *@author:huangLJ
 *@date:2021/7/14 13:31
 */
class DefaultLoader():DownLoader {

    private val config  = DownLoader.DefaultFootConfig()
    private lateinit var textView:TextView
    private lateinit var frameLayout:FrameLayout
    override fun createLoaderView(refreshLayout: PullRefreshLayout): View {
        textView = TextView(refreshLayout.context)
        frameLayout = FrameLayout(refreshLayout.context)
        val layoutParams = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)
        frameLayout.layoutParams = layoutParams


        textView.layoutParams = layoutParams
        textView.setPadding(0,DensityUtil.dip2px(20f),0,DensityUtil.dip2px(20f))

        textView.gravity = Gravity.CENTER
        frameLayout.addView(textView)
        return frameLayout
    }

    override fun getConfig(): DownLoader.LoaderConfig {
        return config
    }

    override fun onDownBegin(refreshView: PullRefreshLayout) {
        textView.text = "别看了，我是你得不到的人!"
    }

    override fun onPositionChange(refreshView: PullRefreshLayout, status: Byte, dy: Int, currentDistance: Int) {

    }

    override fun onLoading(refreshView: PullRefreshLayout) {
        textView.text = "你的坚持打动了我!"
    }

    override fun onReset(refreshView: PullRefreshLayout, pullRelease: Boolean) {
        textView.text = "真无趣，这就放弃了!"
    }

    override fun onPullLoadedFinish(pullRefreshLayout: PullRefreshLayout) {
        textView.text = "对不起，我放弃了!"
    }

}